package com.sanjiahantang.youjiarole.module.common.beans;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.module.login.beans.LoginBean;

import java.util.List;

/**
 * Created by zy on 2018/1/3.
 */

public class RoleStateBean extends BaseBean {
    private String data;

    public List<LoginBean.Role> getData() {
        return new Gson().fromJson(data,new TypeToken<List<LoginBean.Role>>(){}.getType());
    }

    public void setData(String data) {
        this.data = data;
    }

    //1未通过 0 审核中 2 通过
    public int getRoleState(){
        int state = 1;
        List<LoginBean.Role> roleList = getData();
        for (int i = 0;i < roleList.size();i++){
            if (roleList.get(i).getRoleState() == 2){
                state = 2;
                break;
            }else if (roleList.get(i).getRoleState() == 0){
                state = 0;
            }
        }
        return state;
    }

    public boolean hasCheckingRole(){
        List<LoginBean.Role> roleList = getData();
        for (int i = 0;i < roleList.size();i++){
            if (roleList.get(i).getRoleState() == 0){
                return true;
            }
        }
        return false;
    }

    public String getRoleId(){
        List<LoginBean.Role> roleList = getData();
        if (roleList == null || roleList.size() == 0){
            return "";
        }
        String roleId = "";
        for (int i = 0;i < roleList.size();i++){
            if (roleList.get(i).getRoleState() == 2){
                roleId += roleList.get(i).getRoleId() + ",";
            }

        }
        if (!TextUtils.isEmpty(roleId) && roleId.length() > 0){
            roleId = roleId.substring(0,roleId.length() - 1);
        }

        return roleId;
    }
}
